package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.ProductSortTwo;
import cn.wolfcode.crm.service.IProductSortTwoService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("productSortTwo")
public class ProductSortTwoController {
    @Autowired
    private IProductSortTwoService productSortTwoService;
    @RequestMapping("query")
    @ResponseBody
    public Object selectAll() {
        //将数据转换成json格式
        List<ProductSortTwo> productSortTwos = productSortTwoService.selectAll();
        return productSortTwos;
    }
    @RequestMapping("queryBySn")
    @ResponseBody
    public Object queryBySn(String sn) {
        //将数据转换成json格式
        List<ProductSortTwo> productSortTwos = productSortTwoService.selectBySn(sn);
        return productSortTwos;
    }

    //通过sn查询
    @RequestMapping("selectBySn")
    @ResponseBody
    public Object selectBySn(String sn) {
        //将数据转换成json格式
        List<ProductSortTwo> productSortTwos = productSortTwoService.selectBySn(sn);
        return productSortTwos;
    }

    @RequestMapping("view")
    public String view(Model model, Long id) {
        return "/productSortTwo/productSortTwo";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate( ProductSortTwo productSortTwo) {
        productSortTwoService.saveOrUpdate(productSortTwo);
        return new JSONResult();
    }
    
    @RequestMapping("delete")
    @ResponseBody
    public Object delete( Long id) {
        productSortTwoService.deleteByPrimaryKey(id);
        return new JSONResult();
    }

    //通过一级分类sn查询二级分类
    @RequestMapping("selectByParentSn")
    @ResponseBody
    public Object selectByParentSn(String sn) {
        //将数据转换成json格式
        List<ProductSortTwo> sortTwos = productSortTwoService.selectByParentSn(sn);
        return sortTwos;
    }
}
